package poler.model.domain
{
	
	import com.salesforce.Util;
	import com.salesforce.objects.SObject;
	
	import mx.collections.ArrayCollection;
	import mx.controls.DateField;
	
	import poler.model.vo.voView1.DGDetails;
	
	[Bindable]
	public class domainView1
	{

		public var Base64String:String = '';
		public var acContactIds:Array = new Array();
		public var acDetails:ArrayCollection = new ArrayCollection();
		public var arBase64String:Array = new Array();
		public var bViewVisible:Boolean = false;
		
		public function _setBase64String(sArr:ArrayCollection):void
		{
			acContactIds  = new Array();
			Base64String = '';
			for each(var param:Object in sArr){
				acContactIds.push(param.Id);
				if(param.Data__c != null){
					Base64String += param.Data__c == 'null' ? '':param.Data__c;
				}
			}
			trace('Base64String: '+Base64String.length+' acContactsid: '+acContactIds.length);
		}
		public function _replaceDetails(pBook:ArrayCollection):void
		{
			acDetails = _setVO(pBook);
		}
		private function _setVO(ac:ArrayCollection):ArrayCollection{
			var newAC:ArrayCollection = new ArrayCollection();
			for each(var obj:SObject in ac){
				var vo:DGDetails = new DGDetails();
				vo.Id = obj.Id;
				vo.Title = obj.Title;
				vo.Name = obj.Name;
				vo.Birthdate = obj.Birthdate ? DateField.dateToString(Util.stringToDate(obj.Birthdate),'MM/DD/YYYY') : null;
				vo.Phone = obj.Phone;
				vo.Department = obj.Department;
				newAC.addItem(vo);
			}
			return newAC;
		}
		public function _toSObjectArray(vmodel:Object):Array{
			
			var vo:SObject = new SObject('Contact');
			vo.Title = vmodel.Title;
			if(vmodel.FirstName != null) vo.Firstname = vmodel.FirstName;
			if(vmodel.LastName != null) vo.Lastname = vmodel.LastName;
			vo.Birthdate = vmodel.Birthdate;
			vo.Phone = vmodel.Phone;
			vo.Department = vmodel.Department;
			if(vmodel.Id != null) vo.Id = vmodel.Id;
			return ([vo]);			
		}
		public function _addDetails(pBook:DGDetails):void
		{
			acDetails.addItem(pBook);
		}
		

	}
}